<?php
    session_start();
    $_SESSION["P0"] = 'products.php';  
    require 'crud/CustomSecurity.class.php';
    require 'common/Utility.php';
    require 'db/configuration.php';
    require 'crud/Products.class.php';
	require 'crud/GenProduct.class.php';
    loginCheck();
    loadDB();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="bg">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
    <link rel="stylesheet" type="text/css" href="css/page.css" />
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <link rel="stylesheet" type="text/css" href="css/generalProduct.css" />
    <link rel="stylesheet" type="text/css" href="css/add-product.css" />
    <link rel="stylesheet" href="js/autocomplete/jquery.autocomplete.css" type="text/css" />

    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
  	<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
	<title>Добави продукт</title>
	<meta name="author" content="Dimtiar Giormov">
	
</head>
    <body>
    <?php 
		$crud = new Products(con());

		if (isset($_POST['brand'])){
			if (count($crud->haveProduct($_POST['brand'], $_POST['genProduct'])) == 0){
				$crud->add($_POST['brand'], $_POST['genProduct']);
				echo "<script language=javascript> window.top.location.reload(1); </script>";
			} else {
				echo "<div id='message' class='message'>Продуктът съществува в списъка.</div>";
			}
			
		} 
	?>
        	<div id="add-product">
			<form action="add_product.php" name="addproduct" method="post" autocomplete="off">
    			<div id="add-product-left">
    				<ol>
    					<li>търговско име:</li>
    					<li>продукт:</li>
    					<li><input class="table-submit" type="submit" value="Add"></li>
    				</ol>
    			</div>  
    			<div id="add-product-right">
    				<ol>
    					<li><input class="table-input" type="text" id="testinput" name="brand"></li>
    					<li>
    					<?php
    					$productType = new GenProduct(con());
    					$products = $productType->getByCategory();
    					generateCombo($products, null, 'genProduct');
?>
						</li>
					</ol>
				</div>
			</form>
		</div>
	
	 <script>
  $(document).ready(function(){
	  $("#testinput").autocomplete('test2.php');
		 setTimeout("$(\"input[name='brand']\").focus();", 100);
	
  });
  </script>
    </body>
</html>